home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / bc_ti / ti418.asc < prev    next >
Text File  |  1992-02-24  |  23KB  |  859 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  TURBO C                               NUMBER : 418
  9.   VERSION  :  1.0/1.5
  10.        OS  :  MS-DOS
  11.      DATE  :  February 23, 1988                     PAGE  : 1/14
  12.  
  13.     TITLE  :  EXTENDED FILE I/O LIBRARY
  14.  
  15.  
  16.  
  17.  
  18.   The following is public domain information that has been uploaded
  19.   to  our Forum on CompuServe.  As a courtesy to our users that  do
  20.   not  have  immediate  access  to  CompuServe,  Technical  Support
  21.   distributes these routines free of charge.
  22.  
  23.   However,  because these routines are public domain programs,  not
  24.   developed by Borland International,  we are unable to provide any
  25.   technical support or assistance using these routines. If you need
  26.   assistance   using   these   routines,    or   are   experiencing
  27.   difficulties,  we  recommend  that you log  onto  CompuServe  and
  28.   request  assistance  from the Forum members that developed  these
  29.   routines.
  30.  
  31.   Written by
  32.     Randy Forgaard,  CompuServe 70307,521
  33.  
  34.   Translated to Turbo C by
  35.     Charles Jazdzewski
  36.  
  37.   Many   thanks   to  Bela  Lubkin, (CompuServe   76703,3015)   for
  38.   masterminding   this   idea,   and  Kim   Kokkonen,   (CompuServe
  39.   72457,2131)  for  helping me debug it.   For more  discussion  of
  40.   Handle Tables and the implementation of DOS  redirection,  please
  41.   see  Stan Mitchell,  "Command Line Redirection," PC Tech Journal,
  42.   January 1986, Page 44.
  43.  
  44.   Due to a limitation of DOS,  Turbo  C, version 1.5 only allows up
  45.   to 15 files at a time  to  be  open.  The following module allows
  46.   you  to have up to 96 files open simultaneously under DOS 2.0  or
  47.   2.1, or 252 files open simultaneously under DOS  3.0  or greater.
  48.   This module, in its current form, CANNOT be used with streams nor
  49.   networks.
  50.  
  51.   To use this module edit your CONFIG.SYS file (see the  DOS manual
  52.   for details), so that it includes a line  that  says "FILES=XXX".
  53.   XXX should be a version that is 3 greater than the maximum number
  54.   files  you  wish  to  open,  and  should  not  exceed 99 (for DOS
  55.   2.0/2.1) or 255 (for DOS 3.0 and higher). Under  any  version  of
  56.   DOS, the minimum allowable value for XXX is 8. Then,  reboot your
  57.   computer so that the FILES=XXX parameter takes hold.
  58.  
  59.   Running  the sample program at the bottom of this file will  tell
  60.   you the maximum number of files you can open at once. (Usually 96
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  TURBO C                               NUMBER : 418
  75.   VERSION  :  1.0/1.5
  76.        OS  :  MS-DOS
  77.      DATE  :  February 23, 1988                     PAGE  : 1/14
  78.  
  79.     TITLE  :  EXTENDED FILE I/O LIBRARY
  80.  
  81.  
  82.  
  83.  
  84.   or  252,  unless  a resident program has opened  some  files  and
  85.   they have not been closed).
  86.  
  87.   THE TECHNICAL DETAILS:
  88.  
  89.   Much  of the following information is not documented in  the  DOS
  90.   Technical Reference manual.
  91.  
  92.   Under  DOS 1.0 and 1.1,  all files were accessed via File Control
  93.   Blocks (FCB's).  There was no limit to the number of FCB's that a
  94.   program could use,  so there was no limit to the number of  files
  95.   open simultaneously.
  96.  
  97.   Under  DOS 2.0 and greater,  an alternate (and preferable) method
  98.   of  accessing  files was introduced which uses a  2-byte  integer
  99.   called  a  "handle"  to refer to a  file.   A  "handle"  file  is
  100.   described  using  a data structure called a Device Control  Block
  101.   (DCB).   However,  DOS provides the storage space for all  DCB's,
  102.   rather  than having the application program store the  DCB's,  so
  103.   the  number of available DCB's is limited to the amount of  space
  104.   that  DOS  has  set  aside  for  them.   The  maximum  number  of
  105.   files/devices  that can be open simultaneously is the  number  of
  106.   slots  available in the DCB Table created by DOS.   The DCB's  in
  107.   the DCB Table are consecutively numbered, starting with 0.  DCB's
  108.   0,  1, and 2 are predefined by DOS to correspond to the AUX, CON,
  109.   and  PRN devices,  respectively.   All remaining DCB's in the DCB
  110.   Table  are  available for files or devices  used  by  application
  111.   programs.
  112.  
  113.   So that I/O redirection can be supported, the DCB numbers are not
  114.   used directly when accessing files.   Instead, a file "handle" is
  115.   used.   A  "handle" is an index into a 20-byte array,  called the
  116.   Handle  Table,  which  is  located at offset 18H of  the  Program
  117.   Segment  Prefix (PSP) for a program (for a general discussion  of
  118.   the PSP,  see the DOS Technical Reference manual).   Each element
  119.   of the Handle Table is the DCB number of a file or  device.   The
  120.   value  at index "handle" in the Handle Table is the DCB number of
  121.   the file or device that implements that file  handle.   Thus,  if
  122.   the  value 8 is in the 6th byte of the Handle Table,  the  handle
  123.   "6" refers to the file (or device) described by the DCB in slot 8
  124.   of the DCB Table.   If a handle is not currently being used,  its
  125.   entry  in  the Handle Table is FFH.   DOS predefines the first  5
  126.   handles to be primary input,  primary output,  error,  auxiliary,
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  TURBO C                               NUMBER : 418
  141.   VERSION  :  1.0/1.5
  142.        OS  :  MS-DOS
  143.      DATE  :  February 23, 1988                     PAGE  : 1/14
  144.  
  145.     TITLE  :  EXTENDED FILE I/O LIBRARY
  146.  
  147.  
  148.  
  149.  
  150.   and printer, so the first 5 entries in the Handle Table are 1, 1,
  151.   1,  0,  and 2,  corresponding to the DCB numbers for the CON (1),
  152.   AUX  (0),  and PRN (2) devices.   This leaves only  15  available
  153.   handles for opening files (or new devices).
  154.  
  155.   Every time a new handle file is opened,  a new handle gets  used.
  156.   Since there are only 20 slots available in the Handle Table for a
  157.   program, DOS only allows a "process" to have a maximum of 20 file
  158.   handles  in  use  simultaneously  (and the first  5  entries  are
  159.   predefined,  as just noted,  unless those handles get closed  and
  160.   reused).  Every new handle file requires a unique handle, so only
  161.   20 files/devices can be open at the same time by a single process
  162.   (unless  FCB's  are used).   (A "process" is any program  spawned
  163.   using  the DOS EXEC function call.   A process can be invoked  by
  164.   COMMAND.COM, or by another program.)  There can be many more than
  165.   20 DCB's in the DCB Table,  so the real limitation is in the size
  166.   of the Handle Table in the PSP.
  167.  
  168.   The  size  of  the  DCB  Table  (i.e.,   the  maximum  number  of
  169.   files/devices  that  can  be open  simultaneously  in  the  whole
  170.   computer)  is controlled by the FILES=XXX entry in the CONFIG.SYS
  171.   file.   The minimum number of slots is 8.  Under DOS 2.0/2.1, the
  172.   maximum number is 99,  and under DOS 3.0 and higher,  the maximum
  173.   is 255.   As previously mentioned,  the first three of these  DCB
  174.   slots are occupied by the AUX, CON, and PRN devices.
  175.  
  176.   A  single  program  can  use all of the DCB's in  the  DCB  Table
  177.   (except for the 3 reserved by DOS) all on its own, by effectively
  178.   bypassing  the  Handle Table in the PSP,  except on  a  temporary
  179.   basis.   The program can accomplish this feat by using, say, only
  180.   one entry in the Handle Table for all of its files.   Instead  of
  181.   allowing  DOS to store the DCB numbers in the Handle  Table,  the
  182.   program can store these numbers elsewhere.  Then, to manipulate a
  183.   file using DOS, the program can temporarily put the DCB number of
  184.   that  file into a designated slot in the Handle Table,  pass  the
  185.   index  of that table slot (i.e.,  that "handle") to DOS,  and DOS
  186.   will operate on that handle/DCB number.  In this way, DOS  can be
  187.   fooled into accessing up   to 96 (or 252) different files/devices
  188.   using a single  handle entry in the Handle Table.
  189.  
  190.   To obtain the address of the Handle Table, which is at offset 18H
  191.   in  the PSP,  the program needs to find the address of  its  PSP.
  192.   To do this we use  the  DOS  function  call  62H,    "Get Program
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  TURBO C                               NUMBER : 418
  207.   VERSION  :  1.0/1.5
  208.        OS  :  MS-DOS
  209.      DATE  :  February 23, 1988                     PAGE  : 1/14
  210.  
  211.     TITLE  :  EXTENDED FILE I/O LIBRARY
  212.  
  213.  
  214.  
  215.  
  216.   Segment Prefix  Address (PSP)."   This function call is available
  217.   in DOS 3.0  and higher.   There is an  identical function call in
  218.   DOS  2.0/2.1,  but its function number is 51H, and it   is    not
  219.   documented.      Function 51H is also available  in  DOS 3.0/3.1.
  220.   However,  for  upward-compatibility reasons with  future versions
  221.   of DOS,   we  will  use  the  undocumented 51H function  with DOS
  222.   2.0/2.1  (since we know 51H is available  in  those  versions  of
  223.   DOS),  and  use  62H  for  DOS 3.0 and higher  (since  62H  is  a
  224.   documented  function).   There  is no such function call  in  DOS
  225.   1.0/1.1,  but the technique below will not work with those  early
  226.   versions of DOS anyway,  since they did not provide file handles.
  227.  
  228.   /* EIO.C: Extended IO object module ----------------------------
  229.    *    This module bypasses the normal 20 open file per-process
  230.    *    limitation of DOS 2.0 and 3.0.  These routines are only
  231.    *    limited by the number of files allotted for in the
  232.    *    "FILES" statement in the config.sys file.
  233.    * -------------------------------------------------------------
  234.    */
  235.   #include <stdio.h>
  236.   #include <io.h>
  237.   #include <dos.h>
  238.   #include <process.h>
  239.  
  240.   #define UNUSEDHANDLE 0xFF
  241.  
  242.   /****************  Static Variables  ***************/
  243.   /* HandleTable -------------------------------------
  244.    *     Pointer to the program's file handle table
  245.    *--------------------------------------------------
  246.    */
  247.   static unsigned char far *HandleTable = NULL;
  248.  
  249.   /* eioHandle ----------------------------------------
  250.    *     The file handle that this package will use
  251.    * --------------------------------------------------
  252.    */
  253.   static int eioHandle = 20;
  254.  
  255.   /****************  Internal Functions  ****************/
  256.  
  257.   /* GetHandleTableAddr() ------------------------------
  258.    *   This function gets the process file handle table
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  TURBO C                               NUMBER : 418
  273.   VERSION  :  1.0/1.5
  274.        OS  :  MS-DOS
  275.      DATE  :  February 23, 1988                     PAGE  : 1/14
  276.  
  277.     TITLE  :  EXTENDED FILE I/O LIBRARY
  278.  
  279.  
  280.  
  281.  
  282.    *   location from DOS.
  283.    * ---------------------------------------------------
  284.    */
  285.   static unsigned char far *GetHandleTableAddr(void)
  286.   {
  287.       union REGS regs;
  288.  
  289.       /* Determine which DOS function to use to get the PSP
  290.        *   0x51 in 2.x (undocumented)
  291.        *   0x62 in 3.x (documented)
  292.        */
  293.       switch( _osmajor )
  294.       {
  295.           case 0:
  296.           case 1:
  297.               fputs("This program only works with DOS 2.0 and"
  298.                     " higher\n",stderr);
  299.               exit(3);
  300.           case 2:
  301.               regs.h.ah = 0x51;
  302.               break;
  303.           default:
  304.               regs.h.ah = 0x62;
  305.               break;
  306.       }
  307.  
  308.       int86(0x21,®s,®s);
  309.  
  310.       return (unsigned char far *) MK_FP(regs.x.bx, 0x18);
  311.   }
  312.  
  313.  
  314.   /************ Externally Assessable routines *************/
  315.  
  316.   /* eopen() ------------------------------------------------
  317.    *    Opens a file and return its extended file handle.
  318.    *    It replaces open().
  319.    * --------------------------------------------------------
  320.    */
  321.   int eopen(char *pathname, int access, int permiss)
  322.   {
  323.        int handle;
  324.        int SaveDcb;
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.   PRODUCT  :  TURBO C                               NUMBER : 418
  339.   VERSION  :  1.0/1.5
  340.        OS  :  MS-DOS
  341.      DATE  :  February 23, 1988                     PAGE  : 1/14
  342.  
  343.     TITLE  :  EXTENDED FILE I/O LIBRARY
  344.  
  345.  
  346.  
  347.  
  348.        /* Make sure we have the handle table's address */
  349.        if ( !HandleTable )
  350.            HandleTable = GetHandleTableAddr();
  351.  
  352.        /* Physically open the file */
  353.        if ( (handle = open(pathname, access, permiss)) == -1 )
  354.            return -1;
  355.  
  356.        /* Save the data control block */
  357.        SaveDcb = HandleTable[handle];
  358.  
  359.        /* If we don't have a handle to play with, use this one,
  360.         * else make it free again
  361.         */
  362.        if ( eioHandle > 19 )
  363.            eioHandle = handle;
  364.        else
  365.            HandleTable[handle] = UNUSEDHANDLE;
  366.  
  367.        return SaveDcb;
  368.   }
  369.  
  370.   /* eclose() --------------------------------------------------
  371.    *    This routine replaces close().
  372.    * -----------------------------------------------------------
  373.    */
  374.   int eclose(int handle)
  375.   {
  376.       HandleTable[eioHandle] = handle;
  377.       return close(eioHandle);
  378.   }
  379.  
  380.   /* eread() ---------------------------------------------------
  381.    *    Replaces read().
  382.    * -----------------------------------------------------------
  383.    */
  384.   int eread(int handle, void *buf, int nbyte)
  385.   {
  386.       HandleTable[eioHandle] = handle;
  387.       return read(eioHandle, buf, nbyte);
  388.   }
  389.  
  390.   /* ewrite() --------------------------------------------------
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.   PRODUCT  :  TURBO C                               NUMBER : 418
  405.   VERSION  :  1.0/1.5
  406.        OS  :  MS-DOS
  407.      DATE  :  February 23, 1988                     PAGE  : 1/14
  408.  
  409.     TITLE  :  EXTENDED FILE I/O LIBRARY
  410.  
  411.  
  412.  
  413.  
  414.    *    Replaces write().
  415.    * -----------------------------------------------------------
  416.    */
  417.   int ewrite(int handle, void *buf, int nbyte)
  418.   {
  419.       HandleTable[eioHandle] = handle;
  420.       return write(eioHandle, buf, nbyte);
  421.   }
  422.  
  423.   /* elseek() --------------------------------------------------
  424.    *    Replaces lseek().
  425.    * -----------------------------------------------------------
  426.    */
  427.   long elseek(int handle, long offset, int fromwhere)
  428.   {
  429.       HandleTable[eioHandle] = handle;
  430.       return lseek(eioHandle, offset, fromwhere);
  431.   }
  432.   /* ecreat() --------------------------------------------------
  433.    *    Replaces creat().
  434.    * -----------------------------------------------------------
  435.    */
  436.   int ecreat(char *filename, int permiss)
  437.   {
  438.        int handle;
  439.        int SaveDcb;
  440.  
  441.        /* Make sure we have the handle table's address */
  442.        if ( !HandleTable )
  443.            HandleTable = GetHandleTableAddr();
  444.  
  445.        /* Physically open the file */
  446.        if ( (handle = creat(filename, permiss)) == -1 )
  447.            return -1;
  448.  
  449.        /* Save the data control block */
  450.        SaveDcb = HandleTable[handle];
  451.  
  452.        /* If we don't have a handle to play with, use this one,
  453.         * else make it free again
  454.         */
  455.        if ( eioHandle > 19 )
  456.            eioHandle = handle;
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.   PRODUCT  :  TURBO C                               NUMBER : 418
  471.   VERSION  :  1.0/1.5
  472.        OS  :  MS-DOS
  473.      DATE  :  February 23, 1988                     PAGE  : 1/14
  474.  
  475.     TITLE  :  EXTENDED FILE I/O LIBRARY
  476.  
  477.  
  478.  
  479.  
  480.        else
  481.            HandleTable[handle] = UNUSEDHANDLE;
  482.  
  483.        return SaveDcb;
  484.   }
  485.  
  486.   /* ecreatnew() -----------------------------------------------
  487.    *    Replaces creatnew().
  488.    * -----------------------------------------------------------
  489.    */
  490.   int ecreatnew(char *filename, int attrib)
  491.   {
  492.        int handle;
  493.        int SaveDcb;
  494.  
  495.        /* Make sure we have the handle table's address */
  496.        if ( !HandleTable )
  497.            HandleTable = GetHandleTableAddr();
  498.  
  499.        /* Physically open the file */
  500.        if ( (handle = creatnew(filename, attrib)) == -1 )
  501.            return -1;
  502.  
  503.        /* Save the data control block */
  504.        SaveDcb = HandleTable[handle];
  505.  
  506.        /* If we don't have a handle to play with, use this one,
  507.         * else make it free again
  508.         */
  509.        if ( eioHandle > 19 )
  510.            eioHandle = handle;
  511.        else
  512.            HandleTable[handle] = UNUSEDHANDLE;
  513.  
  514.        return SaveDcb;
  515.   }
  516.  
  517.   /* ecreattemp() ----------------------------------------------
  518.    *    Replaces creattemp().
  519.    * -----------------------------------------------------------
  520.    */
  521.   int ecreattemp(char *filename, int attrib)
  522.   {
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.   PRODUCT  :  TURBO C                               NUMBER : 418
  537.   VERSION  :  1.0/1.5
  538.        OS  :  MS-DOS
  539.      DATE  :  February 23, 1988                     PAGE  : 1/14
  540.  
  541.     TITLE  :  EXTENDED FILE I/O LIBRARY
  542.  
  543.  
  544.  
  545.  
  546.        int handle;
  547.        int SaveDcb;
  548.  
  549.        /* Make sure we have the handle table's address */
  550.        if ( !HandleTable )
  551.            HandleTable = GetHandleTableAddr();
  552.  
  553.        /* Physically open the file */
  554.        if ( (handle = creattemp(filename, attrib)) == -1 )
  555.            return -1;
  556.  
  557.        /* Save the data control block */
  558.        SaveDcb = HandleTable[handle];
  559.  
  560.        /* If we don't have a handle to play with, use this one,
  561.         * else make it free again
  562.         */
  563.        if ( eioHandle > 19 )
  564.            eioHandle = handle;
  565.        else
  566.            HandleTable[handle] = UNUSEDHANDLE;
  567.  
  568.        return SaveDcb;
  569.   }
  570.  
  571.   /* eeof() ----------------------------------------------------
  572.    *    Replaces eeof().
  573.    * -----------------------------------------------------------
  574.    */
  575.   int eeof(int handle)
  576.   {
  577.       HandleTable[eioHandle] = handle;
  578.       return eof(eioHandle);
  579.   }
  580.  
  581.   /* efilelength() --------------------------------------------
  582.    *     Replaces filelength().
  583.    * ----------------------------------------------------------
  584.    */
  585.   long efilelength(int handle)
  586.   {
  587.       HandleTable[eioHandle] = handle;
  588.       return filelength(eioHandle);
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.   PRODUCT  :  TURBO C                               NUMBER : 418
  603.   VERSION  :  1.0/1.5
  604.        OS  :  MS-DOS
  605.      DATE  :  February 23, 1988                     PAGE  : 1/14
  606.  
  607.     TITLE  :  EXTENDED FILE I/O LIBRARY
  608.  
  609.  
  610.  
  611.  
  612.   }
  613.  
  614.   /* egetftime() ----------------------------------------------
  615.    *     Replaces getftime().
  616.    * ----------------------------------------------------------
  617.    */
  618.   int egetftime(int handle, struct ftime *ftimep)
  619.   {
  620.  
  621.       HandleTable[eioHandle] = handle;
  622.       return getftime(eioHandle, ftimep);
  623.   }
  624.  
  625.   /* esetftime() ---------------------------------------------
  626.    *     Replaces setftime().
  627.    * ---------------------------------------------------------
  628.    */
  629.   int esetftime(int handle, struct ftime *ftimep)
  630.   {
  631.       HandleTable[eioHandle] = handle;
  632.       return setftime(eioHandle, ftimep);
  633.   }
  634.  
  635.   /* eioctl() -----------------------------------------------
  636.    *    Replace ioctl().
  637.    * --------------------------------------------------------
  638.    */
  639.   int eioctl(int handle, int cmd, int *argdx, int argcx)
  640.   {
  641.       HandleTable[eioHandle] = handle;
  642.       return ioctl(eioHandle, cmd, argdx, argcx);
  643.   }
  644.  
  645.   /* eisatty() ---------------------------------------------
  646.    *    Replaces isatty().
  647.    * -------------------------------------------------------
  648.    */
  649.   int eisatty(int handle)
  650.   {
  651.       HandleTable[eioHandle] = handle;
  652.       return isatty(eioHandle);
  653.   }
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.   PRODUCT  :  TURBO C                               NUMBER : 418
  669.   VERSION  :  1.0/1.5
  670.        OS  :  MS-DOS
  671.      DATE  :  February 23, 1988                     PAGE  : 1/14
  672.  
  673.     TITLE  :  EXTENDED FILE I/O LIBRARY
  674.  
  675.  
  676.  
  677.  
  678.   /* esetmode() --------------------------------------------
  679.    *    Replaces setmode().
  680.    * -------------------------------------------------------
  681.    */
  682.   int esetmode(int handle, unsigned mode)
  683.   {
  684.  
  685.       HandleTable[eioHandle] = handle;
  686.       return setmode(eioHandle, mode);
  687.   }
  688.  
  689.   /* etell() -----------------------------------------------
  690.    *     Replaces tell().
  691.    * -------------------------------------------------------
  692.    */
  693.   long etell(int handle)
  694.   {
  695.       HandleTable[eioHandle] = handle;
  696.       return tell(eioHandle);
  697.   }
  698.  
  699.  
  700.   /*----------------------------------------------------------
  701.    * EIO.H: Header file for the extended file system
  702.    *        This file should be include in any program
  703.    *        using the EIO module.
  704.    *----------------------------------------------------------
  705.    */
  706.  
  707.   #include <io.h>
  708.  
  709.   int  eopen(char *pathname, int access, ... );
  710.   int  eclose(int handle);
  711.   int  eread(int handle, void *buf, int nbyte);
  712.   int  ewrite(int handle, void *buf, int nbytes);
  713.   long elseek(int handle, long offset, int fromwhere);
  714.   int  ecreat(char *filename, int permiss);
  715.   int  ecreatnew(char *filename, int attrib);
  716.   int  ecreattemp(char *filename, int attrib);
  717.   int  eeof(int handle);
  718.   long efilelength(int handle);
  719.   int  egetftime(int handle, struct ftime *ftimep);
  720.   int  esetftime(int handle, struct ftime *ftimep);
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.   PRODUCT  :  TURBO C                               NUMBER : 418
  735.   VERSION  :  1.0/1.5
  736.        OS  :  MS-DOS
  737.      DATE  :  February 23, 1988                     PAGE  : 1/14
  738.  
  739.     TITLE  :  EXTENDED FILE I/O LIBRARY
  740.  
  741.  
  742.  
  743.  
  744.   int  eioctl(int handle, int cmd, ... );
  745.   int  eisatty(int handle);
  746.   int  esetmode(int handle, unsigned mode);
  747.   long etell(int handle);
  748.  
  749.   /* Example  program -- This  program  opens as many Text files as
  750.   it can,    until   DOS  runs out of room in its  DCB  Table.   It
  751.   then reports how many  files  were  successfully opened, writes a
  752.   line  to  each  of them,  then closes and erases  each  of  them.
  753.   Note:  The value  of the FILES=XXX parameter  in  the  CONFIG.SYS
  754.   file  must   be set  to  an appropriate value (see above).     If
  755.   you    change  the FILES=XXX value,  be  sure  to  reboot  before
  756.   running this program.
  757.  
  758.   This program takes a while to run,  due to the heavy disk I/O, so
  759.   running  it  on  a hard disk (or,  even better,  a RAM  disk)  is
  760.   recommended.   Make  sure that you are running the program  in  a
  761.   subdirectory,  so  that you don't run up against the DOS limit on
  762.   the number of allowable files in the root directory of a drive.
  763.   */
  764.  
  765.   #include <stdio.h>
  766.   #include <string.h>
  767.   #include <fcntl.h>
  768.   #include <dos.h>
  769.   #include <process.h>
  770.   #include "eio.h"
  771.  
  772.   #define MAXCOUNT 255
  773.  
  774.   int eiofiles[MAXCOUNT];
  775.   char filename[MAXCOUNT][30];
  776.  
  777.   int main(void)
  778.   {
  779.       int i;
  780.       int count;
  781.  
  782.       printf("Opening file...\n");
  783.       for( i=0;  ;i++)
  784.       {
  785.            strcpy(filename[i],".\\");
  786.            if ( (eiofiles[i] = ecreattemp(filename[i],0)) == -1)
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.   PRODUCT  :  TURBO C                               NUMBER : 418
  801.   VERSION  :  1.0/1.5
  802.        OS  :  MS-DOS
  803.      DATE  :  February 23, 1988                     PAGE  : 1/14
  804.  
  805.     TITLE  :  EXTENDED FILE I/O LIBRARY
  806.  
  807.  
  808.  
  809.  
  810.                break;
  811.            printf("%s opened\n",filename[i]);
  812.       }
  813.  
  814.       count = i;
  815.  
  816.       printf("Successfully opened %d files at the same time.\n"
  817.              "Writing to each file...\n", count);
  818.  
  819.       for (i=0; i<count; i++)
  820.           if ( ewrite(eiofiles[i],"This is a test",
  821.                strlen("This is a test"))
  822.                == 0)
  823.           {
  824.               perror("ewrite");
  825.               return 1;
  826.           }
  827.  
  828.       printf("Closing and erasing each file....\n");
  829.       for (i=0; i<count; i++)
  830.       {
  831.           eclose(eiofiles[i]);
  832.           unlink(filename[i]);
  833.       }
  834.  
  835.       return 0;
  836.   }
  837.  
  838.  
  839.   The following is the project file that can be used to compile the
  840.   above program:
  841.  
  842.   eio.c
  843.   testeio.c
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.